from com.atzl.ui.WindowCCUI import Ui_MainWindow
import os
import sys
from PyQt5.QtWidgets import *
from com.atzl.functions.customerservice.func.BranchCustomerComplaintDataCleansing import Datacleansing

class MyWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        # 设置为全局小部件
        self.ui = Ui_MainWindow()
        self.data = Datacleansing()
        self.ui.setupUi(self)
        global widgets
        widgets = self.ui
        self.ui.pushButton.clicked.connect(self.information_msg)
        self.ui.pushButton_2.clicked.connect(self.ui.textEdit.clear)
        self.ui.pushButton_4.clicked.connect(self.information_msg1)
        self.ui.pushButton_5.clicked.connect(self.ui.textEdit_4.clear)
        self.ui.pushButton_6.clicked.connect(self.ui.textEdit_5.clear)
        self.ui.pushButton_7.clicked.connect(self.information_msg3)
        self.ui.pushButton_7.clicked.connect(self.information_msg2)
        self.ui.pushButton_8.clicked.connect(self.ui.textEdit_2.clear)
        self.ui.pushButton_9.clicked.connect(lambda: os.startfile(r'D:/ExcelData'))
        self.ui.pushButton_10.clicked.connect(self.ui.textEdit_6.clear)

    def parsing_path0(self):
        a = self.ui.textEdit.toPlainText()[8:self.ui.textEdit.toPlainText().find('.xlsx')+5]
        return a

    def parsing_path1(self):
        a = self.ui.textEdit.toPlainText()[self.ui.textEdit.toPlainText().find('.xlsx') +
                                           14:self.ui.textEdit.toPlainText().find('.xlsx',
                                           self.ui.textEdit.toPlainText().find('.xlsx') +
                                           14)+5]
        return a

    def parsing_path2(self):
        a = self.ui.textEdit.toPlainText()[self.ui.textEdit.toPlainText().find('.xlsx',
                                           self.ui.textEdit.toPlainText().find('.xlsx') +
                                           14)+14: self.ui.textEdit.toPlainText().find('.xlsx',
                                           self.ui.textEdit.toPlainText().find('.xlsx',
                                           self.ui.textEdit.toPlainText().find('.xlsx')+14)+14)+5]
        return a

    # 解析 清洗后的客诉表输入框 输入的第一条文件路径
    def parsing_path2_0(self):
        a = self.ui.textEdit_2.toPlainText()[8:self.ui.textEdit_2.toPlainText().find('.xlsx')+5]
        return a

    # 解析 清洗后的客诉表输入框 输入的第二条文件路径
    def parsing_path2_1(self):
        a = self.ui.textEdit_2.toPlainText()[self.ui.textEdit_2.toPlainText().find('.xlsx')+
                                             14:self.ui.textEdit_2.toPlainText().find('.xlsx',
                                             self.ui.textEdit_2.toPlainText().find('.xlsx')+14)+5]
        return a

    # 解析 清洗后的客诉表输入框 输入的第三条文件路径
    def parsing_path2_2(self):
        a = self.ui.textEdit_2.toPlainText()[self.ui.textEdit_2.toPlainText().find('.xlsx' ,
                                             self.ui.textEdit_2.toPlainText().find('.xlsx')+
                                             14)+14: self.ui.textEdit_2.toPlainText().find('.xlsx',
                                             self.ui.textEdit_2.toPlainText().find('.xlsx',
                                             self.ui.textEdit_2.toPlainText().find('.xlsx')+14)+14)+5]
        return a

    # 解析 回访结果表输入框 输入的第一条文件路径
    def parsing_path6_0(self):
        a = self.ui.textEdit_6.toPlainText()[8:self.ui.textEdit_6.toPlainText().find('.xlsx')+5]
        return a

    # 解析 回访结果表输入框 输入的第二条文件路径
    def parsing_path6_1(self):
        a = self.ui.textEdit_6.toPlainText()[self.ui.textEdit_6.toPlainText().find('.xlsx')+
                                             14:self.ui.textEdit_6.toPlainText().find('.xlsx',
                                             self.ui.textEdit_6.toPlainText().find('.xlsx')+14)+5]
        return a

    # 解析 回访结果表输入框 输入的第三条文件路径
    def parsing_path6_2(self):
        a = self.ui.textEdit_6.toPlainText()[self.ui.textEdit_6.toPlainText().find('.xlsx',
                                             self.ui.textEdit_6.toPlainText().find('.xlsx')+14)+14:
                                             self.ui.textEdit_6.toPlainText().find('.xlsx',
                                             self.ui.textEdit_6.toPlainText().find('.xlsx',
                                             self.ui.textEdit_6.toPlainText().find('.xlsx')+14)+14)+5]
        return a

    # 解析 签收表输入框 输入的文件路径
    def parsing_path4(self):
        a = self.ui.textEdit_4.toPlainText().replace('file:///', '')
        return a

    # 解析 匹配表输入框 输入的文件路径
    def parsing_path5(self):
        a = self.ui.textEdit_5.toPlainText().replace('file:///', '')
        return a

    # 调用 生成清洗匹配后的各网点客诉工单表，并判断执行情况并提示
    def information_msg1(self):
        if self.data.summarize(self.parsing_path0(),
                               self.parsing_path1(),
                               self.parsing_path2(),
                               self.parsing_path4(),
                               self.parsing_path5(),
                               self.parsing_path6_0(),
                               self.parsing_path6_1(),
                               self.parsing_path6_2()) is False:
            QMessageBox.information(self, '提示', '文件生成 失败!\n请重试', QMessageBox.Yes, QMessageBox.Yes)
        else:
            QMessageBox.information(self, '提示', '文件生成 成功!', QMessageBox.Yes, QMessageBox.Yes)

    # 调用 读取三网点原始工单方法，并判断执行情况并提示
    def information_msg(self):
        if self.data.read_three_excel(self.parsing_path0(),
                                      self.parsing_path1(),
                                      self.parsing_path2()) is False:
            QMessageBox.information(self, '提示', '读取文件失败!\n请重试',
                                    QMessageBox.Yes, QMessageBox.Yes)
        else:
            QMessageBox.information(self, '提示', '读取文件成功!\n并将单号复制到鼠标粘贴板!\n直接复制到系统中即可!',
                                    QMessageBox.Yes, QMessageBox.Yes)

    # 调用 读取数据透视方法，并判断执行情况并提示
    def information_msg2(self):
        if self.data.data_pivot(self.parsing_path2_0(),
                                self.parsing_path2_1(),
                                self.parsing_path2_2()) is False:
            QMessageBox.information(self, '提示', '数据透视 失败!\n请重试',
                                    QMessageBox.Yes, QMessageBox.Yes)
        else:
            QMessageBox.information(self, '提示', '数据透视 成功!',
                                    QMessageBox.Yes, QMessageBox.Yes)

    # 调用 汇总透视方法，并判断执行情况并提示
    def information_msg3(self):
        if self.data.perspective_data(self.parsing_path2_0(),
                                      self.parsing_path2_1(),
                                      self.parsing_path2_2(),
                                      self.parsing_path5()) is False:
            QMessageBox.information(self, '提示', '数据透视 失败!\n请重试',
                                    QMessageBox.Yes, QMessageBox.Yes)
        else:
            QMessageBox.information(self, '提示', '数据透视 成功!',
                                    QMessageBox.Yes, QMessageBox.Yes)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyWindow()
    ui = MyWindow()
    window.show()
    sys.exit(app.exec_())